<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="企业名称" prop="comName">
        <el-input
          v-model="queryParams.comName"
          placeholder="请输入企业名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      0：待审核；1：有效；2：无效：-->
      <el-form-item label="企业状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
<!--      0:20以下;1:20-150人;2:150-500人;3:500-99人9;4:1000以上-->
      <el-form-item label="企业人数" prop="comNumPeople">
        <el-select v-model="queryParams.comNumPeople" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in numPeopleOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleConfirm"
          v-hasPermi="['env:company:edit']"
        >审核</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="multiple"
          @click="handleConfirmCancel"
          v-hasPermi="['env:company:edit']"
        >取消发布</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['env:company:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="companyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="left" prop="id" />
      <el-table-column label="企业名称" align="left" prop="comName" :show-overflow-tooltip="true"/>
      <el-table-column label="关联用户" align="left" prop="userName" />
      <el-table-column label="企业状态" align="left" prop="status" :formatter="statusFormat"/>

      <el-table-column label="所属行业" align="left" prop="industry" :show-overflow-tooltip="true"/>
<!--      0:20以下;1:20-150人;2:150-500人;3:500-99人9;4:1000以上-->
      <el-table-column label="企业人数" align="left" prop="comNumPeople" :formatter="numPeopleFormat"/>
      <el-table-column label="操作" align="left" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleConfirm(scope.row)"
            v-hasPermi="['env:company:edit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleConfirmCancel(scope.row)"
            v-hasPermi="['env:company:edit']"
          >取消发布</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['env:company:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="删除标志默认0，删除标志：1" prop="del">
          <el-input v-model="form.del" placeholder="请输入删除标志默认0，删除标志：1" />
        </el-form-item>
        <el-form-item label="状态0：待审核；1：有效；2：无效：">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="关联用户ID，来源于招聘用户表ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入关联用户ID，来源于招聘用户表ID" />
        </el-form-item>
        <el-form-item label="关联用户名称，来源于招聘用户表" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入关联用户名称，来源于招聘用户表" />
        </el-form-item>
        <el-form-item label="企业名称" prop="comName">
          <el-input v-model="form.comName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="企业照片" prop="comPhotoUrl">
          <el-input v-model="form.comPhotoUrl" placeholder="请输入企业照片" />
        </el-form-item>
        <el-form-item label="企业地址" prop="comAdr">
          <el-input v-model="form.comAdr" placeholder="请输入企业地址" />
        </el-form-item>
        <el-form-item label="地址经度" prop="comLong">
          <el-input v-model="form.comLong" placeholder="请输入地址经度" />
        </el-form-item>
        <el-form-item label="地址纬度" prop="comLat">
          <el-input v-model="form.comLat" placeholder="请输入地址纬度" />
        </el-form-item>
        <el-form-item label="企业简称" prop="comShortName">
          <el-input v-model="form.comShortName" placeholder="请输入企业简称" />
        </el-form-item>
        <el-form-item label="所属行业" prop="industry">
          <el-input v-model="form.industry" placeholder="请输入所属行业" />
        </el-form-item>
        <el-form-item label="公司人数0:20以下;1:20-150人;2:150-500人;3:500-99人9;4:1000以上" prop="comNumPeople">
          <el-input v-model="form.comNumPeople" placeholder="请输入公司人数0:20以下;1:20-150人;2:150-500人;3:500-99人9;4:1000以上" />
        </el-form-item>
        <el-form-item label="法人代表" prop="comPeople">
          <el-input v-model="form.comPeople" placeholder="请输入法人代表" />
        </el-form-item>
        <el-form-item label="注册资本万元" prop="comRegCapital">
          <el-input v-model="form.comRegCapital" placeholder="请输入注册资本万元" />
        </el-form-item>
        <el-form-item label="成立时间" prop="comRegDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.comRegDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择成立时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公司简介" prop="comDesc">
          <el-input v-model="form.comDesc" placeholder="请输入公司简介" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="备用1" prop="back1">
          <el-input v-model="form.back1" placeholder="请输入备用1" />
        </el-form-item>
        <el-form-item label="备用2" prop="back2">
          <el-input v-model="form.back2" placeholder="请输入备用2" />
        </el-form-item>
        <el-form-item label="备用3" prop="back3">
          <el-input v-model="form.back3" placeholder="请输入备用3" />
        </el-form-item>
        <el-form-item label="备用4" prop="back4">
          <el-input v-model="form.back4" placeholder="请输入备用4" />
        </el-form-item>
        <el-form-item label="备用5" prop="back5">
          <el-input v-model="form.back5" placeholder="请输入备用5" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCompany, getCompany, delCompany, addCompany, updateCompany, exportCompany,confirmCom,confirmCancelCom  } from "@/api/system/company";

export default {
  name: "Company",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 企业信息表格数据
      companyList: [],
      // 状态字典
      statusOptions: [],
      // 企业人数字典
      numPeopleOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        comName: null,
        comNumPeople: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("env_com_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("env_com_num").then(response => {
      this.numPeopleOptions = response.data;
    });
  },
  methods: {
    /** 查询企业信息列表 */
    getList() {
      this.loading = true;
      listCompany(this.queryParams).then(response => {
        this.companyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 简历状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 在职状态字典翻译
    numPeopleFormat(row, column) {
      return this.selectDictLabel(this.numPeopleOptions, row.comNumPeople);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        status: 0,
        comName: null,
        comNumPeople: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加企业信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCompany(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业信息";
      });
    },
    /** 审核按钮操作 */
    handleConfirm(row) {
      const ids = row.id || this.ids;
      confirmCom(ids).then(response => {
        this.msgSuccess("审核成功");
        this.getList();
      })
    },
    /** 取消审核按钮操作 */
    handleConfirmCancel(row) {
      const ids = row.id || this.ids;
      confirmCancelCom(ids).then(response => {
        this.msgSuccess("取消成功");
        this.getList();
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCompany(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCompany(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除企业信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCompany(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有企业信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportCompany(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
